package 国际象棋0710;

import javax.swing.*;
import java.awt.*;

public class UI implements Data{
    JFrame jf = new JFrame("国际象棋");
    MyJPane jp1 = new MyJPane();
    JPanel jp2 = new JPanel();
    JPanel jp3 = new JPanel();
    Tool tool = new Tool();
    Dimension dimension = new Dimension(BW, BH);
    GameListener gl = new GameListener();



    public void initUI(){
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setSize(800,800);
        jf.setLayout(new BorderLayout());
        jf.setLocationRelativeTo(null);

//        jf.setResizable(false);

        jp1.setBackground(Color.white);
        jp1.addMouseListener(gl);
        jp1.gl = gl;
        jf.add(jp1,BorderLayout.CENTER);

        jp2.setBackground(Color.darkGray);
        jp2.setPreferredSize(new Dimension(120,0));
        jf.add(jp2,BorderLayout.EAST);

        jp3.setBackground(Color.white);
        jp3.setPreferredSize(new Dimension(0,100));
        jf.add(jp3,BorderLayout.SOUTH);

        JButton bt1 = new JButton("开始游戏");
        bt1.setPreferredSize(dimension);
        bt1.addActionListener(gl);
        jp2.add(bt1);

        ButtonGroup group = new ButtonGroup();
        JRadioButton jrb1 = new JRadioButton("人人对战", true);
        jrb1.setPreferredSize(dimension);
        jrb1.addActionListener(gl);
        JRadioButton jrb2 = new JRadioButton("人机对战", false);
        jrb2.setPreferredSize(dimension);
        jrb2.addActionListener(gl);
        group.add(jrb1);
        group.add(jrb2);
        jp2.add(jrb1);
        jp2.add(jrb2);
        gl.jrb1 = jrb1;
        gl.jrb2 = jrb2;

        JButton bt2 = new JButton("悔棋");
        bt2.setPreferredSize(dimension);
        bt2.addActionListener(gl);
        jp2.add(bt2);

        JButton bt3 = new JButton("保存对局");
        bt3.setPreferredSize(dimension);
        bt3.addActionListener(gl);
        jp2.add(bt3);

        JButton bt4 = new JButton("查看对局");
        bt4.setPreferredSize(dimension);
        bt4.addActionListener(gl);
        jp2.add(bt4);

        String[] games = tool.getGames();
        JList<String> jList = new JList<>(games);
        jList.setBackground(Color.darkGray);
        jList.setPreferredSize(dimension);
        jList.addListSelectionListener(gl);
        JScrollPane jsp = new JScrollPane(jList);
        jp2.add(jsp);


        jf.setVisible(true);
        gl.g = jp1.getGraphics();
    }

    public static void main(String[] args) {
        UI ui = new UI();
        ui.initUI();
    }

}
